#include "StdAfx.h"
#include "Bucket.h"


Bucket::Bucket(void)
{
	root = gcnew Item();
	root->next = nullptr;
}


void Bucket::push(System::String^ e)
{
	Item^ newItem = gcnew Item();
	newItem->element = e;
	if(!isEmpty())
	{
		newItem->next = root->next;
	}
	root-> next = newItem;
}

System::String^ Bucket::pop()
{
	if(isEmpty()) return " ";
	System::String^ element = root->next->element;
	root->next = root->next->next;
	return element;
}

bool Bucket::isEmpty()
{
	if( root-> next == nullptr) return true;
	else return false;
}

ArrayList^ Bucket::toArray()
{
	
	ArrayList^ elementList = gcnew ArrayList();
	Item^ iter = gcnew Item;
	iter->next = root->next;
	while(iter->next != nullptr)
	{
		iter = iter->next;
		elementList->Add(iter->element);
	}
	return elementList;
}